#include "Engine/Program.h"

#include "Engine/Engine.h"

#include "Graphics/IViewport.h"
#include "Graphics/Colour.h"

namespace tyro
{
	namespace Engine
	{

		Program::Program( void )
			:	engine(0)
		{

		}

		Program::~Program( void )
		{
			// Delete the engine
			delete engine;
		}

		void Program::Run()
		{
			// Try to initialize the program
			if (!Initialise())
			{
				return;
			}

			engine->BeginRendering();


		}

		bool Program::Initialise()
		{
			// Create the engine
			engine = new Engine();
			window = engine->Initialise("Tyro Engine");
			engine->AddFrameListener(this);

			OS::WindowEventUtils::AddWindowEventListener(window, this);

			sceneGraph = engine->CreateSceneGraph();

			CreateCamera();
			CreateViewport();
			CreateScene();

			return true;
		}

		bool Program::FrameQueued( const FrameEvent& evt )
		{
			return true;
		}

		void Program::WindowClosed( Graphics::IRenderWindow* window )
		{
			if (window == this->window)
			{
				
			}
		}

		void Program::CreateCamera()
		{
			camera = sceneGraph->CreateCamera("Main");
		}

		void Program::CreateViewport()
		{
			Graphics::IViewport* viewport1 = window->AddViewport(camera);
			camera->SetAspectRatio(FLOAT_32(viewport1->GetActWidth()) / FLOAT_32(viewport1->GetActHeight()));

			window->AddViewport(camera,1, 0.0f, 0.0f, 0.2f, 0.2f)->SetBackColour(Graphics::Colour::Black);
		}

		void Program::CreateScene()
		{

		}
	}
}
